<html>
<head><meta charset="utf-8"><title>Fix an LLVM pass that eats an optimization attempt · t-compiler/wg-llvm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/index.html">t-compiler/wg-llvm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html">Fix an LLVM pass that eats an optimization attempt</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240236251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240236251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240236251">(May 25 2021 at 19:16)</a>:</h4>
<p>Hello! In <a href="https://github.com/rust-lang/rust/pull/85646">https://github.com/rust-lang/rust/pull/85646</a>, I made a MIR optimization to enhance the quality of the generated assembly, but the LLVM SimplifyCFG removes valuable information for the optimization to be completed by LLVM. I opened an issue on the LLVM bug tracker (<a href="https://bugs.llvm.org/show_bug.cgi?id=50455">https://bugs.llvm.org/show_bug.cgi?id=50455</a>), but I figured my best chances for it to be solved would be to fix it myself. However, I'm not super knowledgeable in LLVM standards: would somebody here know by any chance what would be a good way to solve this specific issue so I can give a shot at implementing it? I figured adding metadata in some places could help, but I have no intuition of what is legal and what would be picked up by later opt passes.</p>



<a name="240242309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240242309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240242309">(May 25 2021 at 20:01)</a>:</h4>
<p>This sounds potentially a pass ordering issue. But I also think that the right way to fix this in Rust would most likely be to add more range metadata more directly to more of the instructions.</p>



<a name="240242387"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240242387" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240242387">(May 25 2021 at 20:02)</a>:</h4>
<p>SimplifyCFG can't and doesn't want to care about this particular situation.</p>



<a name="240245511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240245511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240245511">(May 25 2021 at 20:26)</a>:</h4>
<p>From a phase ordering perspective, the solution would probably be to disable branch to select conversion in the first SimplifyCFG run which runs prior to IPSCCP.</p>



<a name="240245603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240245603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nikita Popov <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240245603">(May 25 2021 at 20:27)</a>:</h4>
<p>From a pure SimplifyCFG perspective, it would be possible to add assumes when folding away a switch with unreachable default, at least if the assume condition can be expressed simply. We actually already do that when folding simple conditional branches to unreachable.</p>



<a name="240248983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240248983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240248983">(May 25 2021 at 20:57)</a>:</h4>
<p>I think I might have made a mistake here: apparently the range metadata on the load instruction rustc emits does not get removed. So the missed opportunity might actually be later down the line.</p>



<a name="240249247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240249247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240249247">(May 25 2021 at 20:59)</a>:</h4>
<p>Here is the code in question:</p>
<div class="codehilite"><pre><span></span><code>start:
  %_12 = alloca i32, align 4
  %residual = alloca i32, align 4
  %self = alloca %&quot;std::result::Result&lt;i32, u32&gt;&quot;, align 4
  %_3 = alloca %&quot;std::ops::ControlFlow&lt;std::result::Result&lt;std::convert::Infallible, u32&gt;, i32&gt;&quot;, align 4
  %1 = alloca %&quot;std::result::Result&lt;i32, u32&gt;&quot;, align 4
  %2 = alloca i64, align 8
  %x = alloca %&quot;std::result::Result&lt;i32, u32&gt;&quot;, align 4
  %3 = bitcast i64* %2 to i8*
  call void @llvm.lifetime.start.p0i8(i64 8, i8* %3)
  store i64 %0, i64* %2, align 8
  %4 = bitcast %&quot;std::result::Result&lt;i32, u32&gt;&quot;* %x to i8*
  %5 = bitcast i64* %2 to i8*
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %4, i8* align 8 %5, i64 8, i1 false)
  %6 = bitcast i64* %2 to i8*
  call void @llvm.lifetime.end.p0i8(i64 8, i8* %6)
  %7 = bitcast %&quot;std::ops::ControlFlow&lt;std::result::Result&lt;std::convert::Infallible, u32&gt;, i32&gt;&quot;* %_3 to i8*
  call void @llvm.lifetime.start.p0i8(i64 8, i8* %7)
  %8 = bitcast %&quot;std::result::Result&lt;i32, u32&gt;&quot;* %self to i8*
  call void @llvm.lifetime.start.p0i8(i64 8, i8* %8)
  %9 = bitcast %&quot;std::result::Result&lt;i32, u32&gt;&quot;* %self to i8*
  %10 = bitcast %&quot;std::result::Result&lt;i32, u32&gt;&quot;* %x to i8*
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %9, i8* align 4 %10, i64 8, i1 false)
  %11 = bitcast %&quot;std::result::Result&lt;i32, u32&gt;&quot;* %self to i32*
  %12 = load i32, i32* %11, align 4, !range !5
  %_8 = zext i32 %12 to i64
  switch i64 %_8, label %bb2 [
    i64 0, label %bb3
    i64 1, label %bb1
  ]
</code></pre></div>



<a name="240249302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240249302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240249302">(May 25 2021 at 20:59)</a>:</h4>
<p>I think it might actually just remove the load that has the range information, which removes the range information entirely</p>



<a name="240249389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240249389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240249389">(May 25 2021 at 21:00)</a>:</h4>
<p>Would there be a way to emit the range information sooner when dealing with enum variants?</p>



<a name="240249495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240249495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240249495">(May 25 2021 at 21:01)</a>:</h4>
<p>for example maybe when allocating "places" in which we will store variants</p>



<a name="240249532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240249532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240249532">(May 25 2021 at 21:01)</a>:</h4>
<p>I don't know if LLVM supports that</p>



<a name="240250544"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240250544" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240250544">(May 25 2021 at 21:10)</a>:</h4>
<p>Do you know of a place that lists where LLVM IR metadata can be appended? The LangRef is quite sparse on this sort of data</p>



<a name="240255546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240255546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240255546">(May 25 2021 at 21:59)</a>:</h4>
<p>the metadata is attached to the SSA value, not the instruction, i.e. <code>%12</code> is known to have that particular range (the result of the load) AFAIK.</p>
<p>(EDIT: on a further reflection: they are the same actually, and it turns out that the instruction used does matter, I was thinking of a different piece of metadata and then internally generalized it to everything else)</p>



<a name="240255566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240255566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240255566">(May 25 2021 at 21:59)</a>:</h4>
<p>Whether its a load insn or something else is irrelevant in this case.</p>



<a name="240255664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240255664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240255664">(May 25 2021 at 22:00)</a>:</h4>
<p>okay! that's actually good news, then?</p>



<a name="240255757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240255757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240255757">(May 25 2021 at 22:01)</a>:</h4>
<p>i have not gotten to look at the IR gen in rustc, but I suspect we should know when generating an SSA value whether it will be assigned to an enum variant, right?</p>



<a name="240255800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240255800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240255800">(May 25 2021 at 22:01)</a>:</h4>
<p>do you have a godbolt link with your test case?</p>



<a name="240255882"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240255882" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240255882">(May 25 2021 at 22:02)</a>:</h4>
<p>unfortunately this is in an unmerged PR</p>



<a name="240255896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240255896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240255896">(May 25 2021 at 22:02)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/85646">https://github.com/rust-lang/rust/pull/85646</a></p>



<a name="240255925"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240255925" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240255925">(May 25 2021 at 22:02)</a>:</h4>
<p>...that I think I just broke</p>



<a name="240255963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240255963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240255963">(May 25 2021 at 22:03)</a>:</h4>
<p>I… don't think you can tell it _just_ from the place or its type.</p>



<a name="240255986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240255986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240255986">(May 25 2021 at 22:03)</a>:</h4>
<p>but you can by seeing if the place is only ever assigned a <code>discriminant(_)</code> expr.</p>



<a name="240256065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256065">(May 25 2021 at 22:04)</a>:</h4>
<p>in an SSA context, is that not easy to determine?</p>



<a name="240256083"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256083" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256083">(May 25 2021 at 22:04)</a>:</h4>
<p>What is an SSA context in this case?</p>



<a name="240256094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256094">(May 25 2021 at 22:04)</a>:</h4>
<p>like, if we're copying from either <code>discriminant(_)</code> or an SSA value that is known to be discriminant</p>



<a name="240256107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256107">(May 25 2021 at 22:04)</a>:</h4>
<p>the context of LLVM IR I meant</p>



<a name="240256128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256128">(May 25 2021 at 22:04)</a>:</h4>
<p>sorry if I'm not precise, I'm not used to this</p>



<a name="240256153"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256153" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256153">(May 25 2021 at 22:05)</a>:</h4>
<p>LLVM IR does not know about disciminants, its way more general.</p>



<a name="240256165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256165">(May 25 2021 at 22:05)</a>:</h4>
<p>yes but we do, right?</p>



<a name="240256191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256191">(May 25 2021 at 22:05)</a>:</h4>
<p>at some point we create an SSA value and we assign it something</p>



<a name="240256208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256208">(May 25 2021 at 22:05)</a>:</h4>
<p>We almost never create SSA values in our codegen.</p>



<a name="240256216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256216">(May 25 2021 at 22:05)</a>:</h4>
<p>can we not use information rustc knows on the something to figure out if it's a discriminant or not?</p>



<a name="240256238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256238">(May 25 2021 at 22:06)</a>:</h4>
<p>I must be confused</p>



<a name="240256275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256275">(May 25 2021 at 22:06)</a>:</h4>
<p>because MIR is not an SSA and its way easier to let LLVM's mem2reg to deal with it.</p>



<a name="240256287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256287">(May 25 2021 at 22:06)</a>:</h4>
<p>I thought an SSA value was like %0, %1, etc</p>



<a name="240256358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256358">(May 25 2021 at 22:07)</a>:</h4>
<p>Well, we create stack allocas most of the time which then are assigned to SSA values, but these values are really more like a pointer to a memory location than a memory location itself.</p>



<a name="240256430"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256430" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256430">(May 25 2021 at 22:07)</a>:</h4>
<p>mem2reg in LLVM later does remove these allocas where possible.</p>



<a name="240256570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256570">(May 25 2021 at 22:09)</a>:</h4>
<p>ah</p>



<a name="240256582"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256582" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256582">(May 25 2021 at 22:09)</a>:</h4>
<p>that makes it... harder</p>



<a name="240256598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256598">(May 25 2021 at 22:09)</a>:</h4>
<p>Anyway, I don't believe you can tell just by looking at a <code>_0 = disciminant(_x)</code> statement that <code>_0</code> is only ever going to be assigned a disciminant.</p>



<a name="240256622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256622">(May 25 2021 at 22:09)</a>:</h4>
<p>because elsewhere in the function body there might be just a plain <code>_0 = const 42</code></p>



<a name="240256628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256628">(May 25 2021 at 22:09)</a>:</h4>
<p>yes in MIR definitely</p>



<a name="240256695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256695">(May 25 2021 at 22:10)</a>:</h4>
<p>I thought the LLVM IR codegen would generate SSA values directly</p>



<a name="240256701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256701">(May 25 2021 at 22:10)</a>:</h4>
<p>in that case I think it would be possible still (?)</p>



<a name="240256725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256725">(May 25 2021 at 22:10)</a>:</h4>
<p>but it's not the case</p>



<a name="240256744"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256744" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256744">(May 25 2021 at 22:10)</a>:</h4>
<p>I think it would necessitate another intermediate IR with different semantics from MIR.</p>



<a name="240256762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256762">(May 25 2021 at 22:11)</a>:</h4>
<p>that would allow to reimplement something like mem2reg.</p>



<a name="240256764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256764">(May 25 2021 at 22:11)</a>:</h4>
<p>would MIR being SSA help?</p>



<a name="240256779"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256779" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256779">(May 25 2021 at 22:11)</a>:</h4>
<p>Sure, but MIR can't be SSA.</p>



<a name="240256783"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256783" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256783">(May 25 2021 at 22:11)</a>:</h4>
<p>why?</p>



<a name="240256862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256862">(May 25 2021 at 22:12)</a>:</h4>
<p>We run a number of analyses on it (e.g. borrowck) that necessitate preserving information that's closer to the source code.</p>



<a name="240256889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256889">(May 25 2021 at 22:12)</a>:</h4>
<p>ah I see</p>



<a name="240256900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256900">(May 25 2021 at 22:12)</a>:</h4>
<p>because I've also found SSA to be very useful for writing optimization</p>



<a name="240256906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256906">(May 25 2021 at 22:13)</a>:</h4>
<p>(TBF I'm going to backtrack on that claim, I'm not ready to prove that it wouldn't be possible to implement borrowck on an SSA-ish IR, and I don't want to bother)</p>



<a name="240256930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256930">(May 25 2021 at 22:13)</a>:</h4>
<p>that's ok</p>



<a name="240256964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240256964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240256964">(May 25 2021 at 22:13)</a>:</h4>
<p>though then I'd love to see an SSA form of MIR</p>



<a name="240257021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257021">(May 25 2021 at 22:14)</a>:</h4>
<p>but that's probably a huge amount of work</p>



<a name="240257040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257040">(May 25 2021 at 22:14)</a>:</h4>
<p>though if it ends up being a new format, optimizations could be ported to it progressively</p>



<a name="240257058"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257058" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257058">(May 25 2021 at 22:14)</a>:</h4>
<p>and then the codegen could use that to generate SSA values directly in LLVM IR</p>



<a name="240257095"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257095" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257095">(May 25 2021 at 22:15)</a>:</h4>
<p>I'm not sure why LLVM-IR is not the SSA IR that you can write optimisations for in the first place, though.</p>



<a name="240257206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257206">(May 25 2021 at 22:16)</a>:</h4>
<p>The only thing that LLVM-IR doesn't really have is ability to work with non-monomorphized code, and whether that'd be a benefit is quite debatable.</p>



<a name="240257335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257335">(May 25 2021 at 22:17)</a>:</h4>
<p><span class="user-mention silent" data-user-id="409735">Théo Degioanni</span> <a href="#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt/near/240255882">said</a>:</p>
<blockquote>
<p>unfortunately this is in an unmerged PR</p>
</blockquote>
<p>A godbolt link of the LLVM IR?</p>



<a name="240257351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257351">(May 25 2021 at 22:17)</a>:</h4>
<p>i.e. not an excerpt of IR, but something that compiles?</p>



<a name="240257374"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257374" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257374">(May 25 2021 at 22:18)</a>:</h4>
<p>right</p>



<a name="240257452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257452">(May 25 2021 at 22:18)</a>:</h4>
<p>I'm not experienced enough to understand what makes MIR opts worth it</p>



<a name="240257468"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257468" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257468">(May 25 2021 at 22:18)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> <a href="#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt/near/240257351">said</a>:</p>
<blockquote>
<p>i.e. not an excerpt of IR, but something that compiles?</p>
</blockquote>
<p>I can give you that</p>



<a name="240257546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257546">(May 25 2021 at 22:19)</a>:</h4>
<p><a href="https://rust.godbolt.org/z/xqhjb1P36">https://rust.godbolt.org/z/xqhjb1P36</a></p>



<a name="240257561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257561">(May 25 2021 at 22:20)</a>:</h4>
<p>godbolt can do so much</p>



<a name="240257608"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257608" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257608">(May 25 2021 at 22:20)</a>:</h4>
<p>MIR optimisations are good where they imcrease the quality/reduce the amount of LLVM-IR we produce.</p>



<a name="240257627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257627">(May 25 2021 at 22:20)</a>:</h4>
<p>They are good in that situation because MIR is generic.</p>



<a name="240257683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257683">(May 25 2021 at 22:21)</a>:</h4>
<p>So for a function that is monomorphized 1000 times, the factor that we amplify by those 1000 times is much smaller when the LLVM-IR we generate is better.</p>



<a name="240257734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257734">(May 25 2021 at 22:21)</a>:</h4>
<p>Okay that makes sense. Then I do believe those optimizations are easier to write in SSA form.</p>



<a name="240257788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257788">(May 25 2021 at 22:22)</a>:</h4>
<p>(ignoring any other factor)</p>



<a name="240257805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257805">(May 25 2021 at 22:22)</a>:</h4>
<p>That's why I like the idea of SSA MIR, that's all.</p>



<a name="240257872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257872">(May 25 2021 at 22:23)</a>:</h4>
<p>That might be the case, but most of the low hanging fruit has been handled just fine as is (inlining, CFG simplifications). One thing that got stuck was various propagations, but that's lacking alias analysis and not SSA.</p>



<a name="240257873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257873">(May 25 2021 at 22:23)</a>:</h4>
<p>Is there a tracking issue on things to do to increase the amount of metadata rustc outputs?</p>



<a name="240257916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240257916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240257916">(May 25 2021 at 22:23)</a>:</h4>
<p>I am very eager to learn and do things so I wonder whether I could help on that front.</p>



<a name="240258051"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240258051" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240258051">(May 25 2021 at 22:25)</a>:</h4>
<blockquote>
<p>Ranges are only for loads, calls and invokes!<br>
 %_8 = zext i32 %12 to i64, !range !5</p>
</blockquote>
<p>welp.</p>



<a name="240258064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240258064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240258064">(May 25 2021 at 22:25)</a>:</h4>
<p>oh no</p>



<a name="240258170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240258170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240258170">(May 25 2021 at 22:26)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> <a href="#narrow/stream/187780-t-compiler.2Fwg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt/near/240257095">said</a>:</p>
<blockquote>
<p>I'm not sure why LLVM-IR is not the SSA IR that you can write optimisations for in the first place, though.</p>
</blockquote>
<p>(there's also the fact that writing opts in C++ is not very appealing <span aria-label="upside down" class="emoji emoji-1f643" role="img" title="upside down">:upside_down:</span> )</p>



<a name="240258211"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240258211" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240258211">(May 25 2021 at 22:27)</a>:</h4>
<p>That said I'm surprised LLVM would have trouble figuring out that range of %_8 is also !5 tbh.</p>



<a name="240258247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240258247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240258247">(May 25 2021 at 22:27)</a>:</h4>
<p>I think it actually just loses that whole code section</p>



<a name="240258311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240258311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240258311">(May 25 2021 at 22:28)</a>:</h4>
<p>because you don't have to go through memory here, so it just drops everything, including the metadata</p>



<a name="240258469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240258469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240258469">(May 25 2021 at 22:30)</a>:</h4>
<p>In my experience the available infrastructure makes much larger difference than the language that is being used (though, of course all else being equal it would be a much more reasonable comparison). Right now alas the infrastructure for MIR opts is very lacking.</p>



<a name="240258770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240258770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240258770">(May 25 2021 at 22:34)</a>:</h4>
<p>As an example, I already said above that we lack e.g. alias analysis, which is preventing us from implementing various propagation passes. Another problem is the fact that updating the MIR data structures with optimized code is a major pain, or at least used to be back then; not sure how it is today, but I would be surprised it changed in meaningful ways.</p>



<a name="240259459"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240259459" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240259459">(May 25 2021 at 22:43)</a>:</h4>
<p>What does “updating the MIR data structures with optimized code” mean?</p>



<a name="240259935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240259935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240259935">(May 25 2021 at 22:48)</a>:</h4>
<p>So MIR basic block is a Vec of Statements and Body is a Vec of BasicBlocks and another Vec of variables.. A lot of stuff refers to elements in these vectors by indices. As thus, if you want to change something, you must make sure that you don't invalidate the indices (which means that you must update the entire body every time you make a change) and even then due to how <code>Vec</code> works removing or adding things to a middle of a <code>Vec</code> is expensive.</p>



<a name="240259971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240259971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240259971">(May 25 2021 at 22:49)</a>:</h4>
<p>if you start adding/removing/updating things often, you quickly run into O(powers-of-n)</p>



<a name="240260165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240260165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240260165">(May 25 2021 at 22:51)</a>:</h4>
<p>Ah I see</p>



<a name="240260258"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240260258" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240260258">(May 25 2021 at 22:52)</a>:</h4>
<p>We have a way to update more efficiently at once, called Patch, but its pretty clunky to use too in my experience.</p>



<a name="240260275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240260275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240260275">(May 25 2021 at 22:53)</a>:</h4>
<p>Barely anything uses that mechanism.</p>



<a name="240260646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240260646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Théo Degioanni <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240260646">(May 25 2021 at 22:57)</a>:</h4>
<p>Thank you for the explanations. I need to head off. I’m a bit bummed out by the range issue however. Hopefully there’s something that can be done still to make the optimisation possible.</p>



<a name="240265474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/187780-t-compiler/wg-llvm/topic/Fix%20an%20LLVM%20pass%20that%20eats%20an%20optimization%20attempt/near/240265474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/187780-t-compiler/wg-llvm/topic/Fix.20an.20LLVM.20pass.20that.20eats.20an.20optimization.20attempt.html#240265474">(May 26 2021 at 00:04)</a>:</h4>
<p>Hmm, it looks like there's no <code>exact</code> flag available for <code>truncate</code>?  Seems like an odd omission, given <code>udiv exact</code> and <code>lshr exact</code> and such. I guess the way to encode it would be <code>shl n[ui]w</code>+<code>[la]shr exact</code>+<code>truncate</code>?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>